Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java 8 Interview Questions and Answers

Question: What is lambda expression?
Answer:
Lambda expression is anonymous function which have set of parameters and a lambda (->) and a function body. You can call it function without name.

Structure of Lambda Expressions:
(Argument List) ->{expression;} or
(Argument List) ->{statements;}

For instance, the Runnable interface is a functional interface, so instead of:
Thread thread = new Thread(new Runnable() {
    public void run() {
        System.out.println("Hello World!");
    }
});
 
Using Lambda you can simply do the following:
Thread thread = new Thread(() -> System.out.println("Hello World!"));

Functional interfaces are usually annotated with the @FunctionalInterface annotation - which is informative and does not affect the semantics.
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook